package com.chunxuan.langquan.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.chunxuan.langquan.MainActivity;
import com.chunxuan.langquan.R;
import com.chunxuan.langquan.base.Global;
import com.chunxuan.langquan.support.util.ActiviceCollector;
import com.ruitu.arad.util.ToastUtils;

/**
 * 有4个按钮的导航页
 */
public class GuidActivity extends AppCompatActivity implements View.OnClickListener {
//    private Button btnCourse,btnZhibo,btnMall,btnMine;
//    private TextView tvCourse,tvZhibo,tvMall,tvMine;
    private LinearLayout llCourseCenter,llLive,llMall,llUser;
    private ImageView ivScan;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        ActiviceCollector.addActivity(this);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
//        setContentView(R.layout.activity_guid1);
//        tvCourse=findViewById(R.id.tv_course);
//        tvZhibo=findViewById(R.id.tv_zhibo);
//        tvMall=findViewById(R.id.tv_mall);
//        tvMine=findViewById(R.id.tv_mine);
//        tvCourse.setOnClickListener(this);
//        tvZhibo.setOnClickListener(this);
//        tvMall.setOnClickListener(this);
//        tvMine.setOnClickListener(this);
        setContentView(R.layout.activity_module);
        llCourseCenter=findViewById(R.id.ll_course_center);
        llLive=findViewById(R.id.ll_course_live);
        llMall=findViewById(R.id.ll_mall);
        llUser=findViewById(R.id.ll_user);
        ivScan=findViewById(R.id.iv_scan);
        llCourseCenter.setOnClickListener(this);
        llLive.setOnClickListener(this);
        llMall.setOnClickListener(this);
        llUser.setOnClickListener(this);
        ivScan.setOnClickListener(this);
    }
//    private long waitTime = 2000;
//    private long touchTime = 0;
//
//    @Override
//    public void onBackPressed() {
//            long currentTime = System.currentTimeMillis();
//            if ((currentTime - touchTime) >= waitTime) {
//                ToastUtils.showShortSafe("再按一次退出程序");
//                touchTime = currentTime;
//            } else {
////                Intent backHome = new Intent(Intent.ACTION_MAIN);//启动一个意图,回到桌面
////                backHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
////                backHome.addCategory(Intent.CATEGORY_HOME);
////                startActivity(backHome);
//                super.onBackPressed();
//            }
//    }
    private long mExitTime;
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //判断用户是否点击了“返回键”
        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            if(Global.IS_SHOW ==0){
                //与上次点击返回键时刻作差
                if ((System.currentTimeMillis() - mExitTime) > 2000) {
                    //大于2000ms则认为是误操作，使用Toast进行提示
                    ToastUtils.showShortSafe("再按一次退出程序");
                    //并记录下本次点击“返回键”的时刻，以便下次进行判断
                    mExitTime = System.currentTimeMillis();
                } else {
                    //小于2000ms则认为是用户确实希望退出程序-调用System.exit()方法进行退出
                    ActiviceCollector.finishAll();
                    finish();
                    System.exit(0);
                }
//            }else if(Global.IS_SHOW ==1){
//                startActivity(GuidActivity.class);
//            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    @Override
    public void onClick(View view) {
        Intent intent=new Intent(GuidActivity.this, MainActivity.class);
        switch (view.getId()){
//            case R.id.tv_course:
//                intent.putExtra("guid_id",0);
//                startActivity(intent);
//                break;
//            case R.id.tv_zhibo:
//                intent.putExtra("guid_id",1);
//                startActivity(intent);
//                break;
//            case R.id.tv_mall:
//                intent.putExtra("guid_id",2);
//                startActivity(intent);
//                break;
//            case R.id.tv_mine:
//                intent.putExtra("guid_id",3);
//                startActivity(intent);
//                break;
            case R.id.ll_course_center:
                intent.putExtra("guid_id",0);
                startActivity(intent);
                finish();
                break;
            case R.id.ll_course_live:
                intent.putExtra("guid_id",1);
                startActivity(intent);
                finish();
                break;
            case R.id.ll_mall:
                intent.putExtra("guid_id",2);
                startActivity(intent);
                finish();
                break;
            case R.id.ll_user:
                intent.putExtra("guid_id",3);
                startActivity(intent);
                finish();
                break;
            case R.id.iv_scan:
                ToastUtils.showShort("敬请期待");
                break;
        }
    }
}